package controllers

import (
	"gogogo/models"

	"github.com/robfig/cron/v3"
)

// 日常定时任务
func DailyGrabDatas() {

}

func SetupAndGo() *cron.Cron {
	c := cron.New()
	// Funcs are invoked in their own goroutine, asynchronously.
	c.AddFunc("@daily", DailyGrabDatas)
	c.AddFunc("*/2 * * * *", SetFlowerState)
	c.Start()
	// Funcs may also be added to a running Cron
	return c
}

func SetFlowerState() {
	// 设置浇花状态
	models.GetInstance().WaterFlowerTimer()
}

func StopAndClean(c *cron.Cron) {
	es := c.Entries()
	for i := 0; i < len(es); i++ {
		c.Remove(es[i].ID)
	}
	c.Stop()
}
